using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UI_PlayerHealthBar : MonoBehaviour
{
    private PlayerStats playerStats;
    private Slider healthSlider;

    private void Awake()
    {
        healthSlider = GetComponentInChildren<Slider>();
    }

    void Start()
    {
        playerStats = PlayerManager.instance.player.GetComponent<PlayerStats>();
        playerStats.OnHealthChanged += UpdateHealthBar;
    }

    private void UpdateHealthBar()
    {
        healthSlider.value = playerStats.CurrentHealth/(float)playerStats.GetMaxHealth();
    }

}
